// UVData.cpp: implementation of the CUVData class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "UVData.h"

#include "../Util/MinUtilExt.h"
#include "../Util/MyProgressWnd.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CUVData::CUVData(CString strFileName, CString strPath) : CFileManager(strFileName, strPath)
{
	m_nUVlightoption = 0;
	m_nProductquantity = 0;
	m_nMaximumsizedeviation = 0;
	m_nUVRangelimitoption = 0;
	m_nMaximumlimit = 0;
	m_nMinimumlimit = 0;
}

CUVData::CUVData(CString strFileName) : CFileManager(strFileName)
{
	m_nUVlightoption = 0;
	m_nProductquantity = 0;
	m_nMaximumsizedeviation = 0;
	m_nUVRangelimitoption = 0;
	m_nMaximumlimit = 0;
	m_nMinimumlimit = 0;
}

CUVData::~CUVData()
{

}

int CUVData::ReadUVData()
{
	char eMsg[200];
	char eMsg1[200];
	CString strSection;
	BOOL ret = TRUE;
	memset(eMsg, 0, sizeof(eMsg));
	memset(eMsg1, 0, sizeof(eMsg1));
	
	CMyProgressWnd ProgWnd(NULL, "UV Data File Loading...");
	ProgWnd.SetRange(0, 17);
	ProgWnd.SetText("Work in progress.\n"
		"Wait a moment.");
	ProgWnd.PeekAndPump();
	/** [System Data]*/
	if(!GetValue("UV Data", "UV Light Option", &m_nUVlightoption))
	{
		sprintf(eMsg, "Could not read [UV Data] UV Light Option items. Would you like to read on the Next item?");
		sprintf(eMsg1, "%s File Read Error!", m_strFileName);
		if(MyMessageBox(eMsg, eMsg1, M_ICONERROR|M_YESNO) == IDNO) return FALSE;
		ret = FALSE;
	}
	ProgWnd.StepIt(); 

	if(!GetValue("UV Data", "Product Quantity", &m_nProductquantity))
	{
		sprintf(eMsg, "Could not read [UV Data] Product Quantity items. Would you like to read on the Next item?");
		sprintf(eMsg1, "%s File Read Error!", m_strFileName);
		if(MyMessageBox(eMsg, eMsg1, M_ICONERROR|M_YESNO) == IDNO) return FALSE;
		ret = FALSE;
	}
	ProgWnd.StepIt();
	
	if(!GetValue("UV Data", "Maximum Size Deviation", &m_nMaximumsizedeviation))
	{
		sprintf(eMsg, "Could not read [UV Data] Maximum Size Deviation items. Would you like to read on the Next item?");
		sprintf(eMsg1, "%s File Read Error!", m_strFileName);
		if(MyMessageBox(eMsg, eMsg1, M_ICONERROR|M_YESNO) == IDNO) return FALSE;
		ret = FALSE;
	}
	ProgWnd.StepIt();
	
	if(!GetValue("UV Data", "UV Range Limit Option", &m_nUVRangelimitoption))
	{
		sprintf(eMsg, "Could not read [UV Data] UV Range Limit Option items. Would you like to read on the Next item?");
		sprintf(eMsg1, "%s File Read Error!", m_strFileName);
		if(MyMessageBox(eMsg, eMsg1, M_ICONERROR|M_YESNO) == IDNO) return FALSE;
		ret = FALSE;
	}
	ProgWnd.StepIt();
	
	if(!GetValue("UV Data", "Maximum Limit", &m_nMaximumlimit))
	{
		sprintf(eMsg, "Could not read [UV Data] Maximum Limit items. Would you like to read on the Next item?");
		sprintf(eMsg1, "%s File Read Error!", m_strFileName);
		if(MyMessageBox(eMsg, eMsg1, M_ICONERROR|M_YESNO) == IDNO) return FALSE;
		ret = FALSE;
	}
	ProgWnd.StepIt();
	
	if(!GetValue("UV Data", "Minimum Limit", &m_nMinimumlimit))
	{
		sprintf(eMsg, "Could not read [UV Data] Minimum Limit items. Would you like to read on the Next item?");
		sprintf(eMsg1, "%s File Read Error!", m_strFileName);
		if(MyMessageBox(eMsg, eMsg1, M_ICONERROR|M_YESNO) == IDNO) return FALSE;
		ret = FALSE;
	}
	ProgWnd.StepIt();
	return ret;   
}

int CUVData::WriteUVData()
{
	char eMsg[200];
	char eMsg1[200];
	CString strSection;
	BOOL ret = TRUE;
	memset(eMsg, 0, sizeof(eMsg));
	memset(eMsg1, 0, sizeof(eMsg1));
	
	if(!MakeBackUpFile())
	{
		if(MyMessageBox("Back Up File create failed. Do you want to continue?", 
			"File Write Error", M_ICONERROR|M_YESNO) == IDNO) 
			return FALSE;
	}
	
	CMyProgressWnd ProgWnd(NULL, "UV Data File Saving...");
	ProgWnd.SetRange(0,17);
	ProgWnd.SetText("Work in progress.\n"
		"Wait a moment.");
	ProgWnd.PeekAndPump();
	/** [System Data]*/
	if(!SetValue("UV Data", "UV Light Option", m_nUVlightoption)) ret = FALSE;
	ProgWnd.StepIt(); 
	if(!SetValue("UV Data", "Product Quantity", m_nProductquantity)) ret = FALSE;
	ProgWnd.StepIt(); 
	if(!SetValue("UV Data", "Maximum Size Deviation", m_nMaximumsizedeviation)) ret = FALSE;
	ProgWnd.StepIt();
	if(!SetValue("UV Data", "UV Range Limit Option", m_nUVRangelimitoption)) ret = FALSE;
	ProgWnd.StepIt();
	if(!SetValue("UV Data", "Maximum Limit", m_nMaximumlimit)) ret = FALSE;
	ProgWnd.StepIt();
	if(!SetValue("UV Data", "Minimum Limit", m_nMinimumlimit)) ret = FALSE;
	ProgWnd.StepIt();

	return ret;
}